Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: make plots with red/blue stripes advected with flow #68

Merged
merged 11 commits into from
May 18, 2017

Conversation

rjleveque
Copy link
Member

In the past I've made animations of shallow water with advected colors only by running Clawpack.

Now I'm working on a tool to do this from the exact Riemann solution. I separated out the code to compute trajectories from the previous code to plot trajectories in the x-t plane in utils/riemann_tools.py, and use it to compute the motion of the edges of the stripes.

So far this is only illustrated in Euler_equations.ipynb, where density is colored red to left and blue to right of contact discontinuity.

I plan to use this in the Prologue notebook for the examples of shallow water equations.

I also plan to extract more of the messy code now in Euler_equations.ipynb and put it in riemann_tools, but welcome comments or suggestions before doing more.

…tripes.

Illustrated in Euler_equations.ipynb where density is colored red to left and blue to right of contact discontinuity.
Also add snapshot_widget option to Traffic_flow.ipynb
…amples.

Added new function to utils/riemann_tools.py to make simple demo plots
and improved setting of x_traj points so stripes are equal width near origin
@rjleveque
Copy link
Member Author

I added an Introduction.ipynb notebook, see #62.

We might want to improve this to allow JSAnimation as an option instead of the widgets so that people viewing the introduction online can see the time evolution.

@ketch ketch mentioned this pull request Apr 25, 2017
12 tasks
@ketch
Copy link
Member

ketch commented Apr 25, 2017

Looks good! Moving the stripe plotting code to riemann_utils and incorporating it as a standard option with make_plot_function seems like a good idea.

I wrote a JSAnimation version of the stripe plotting in Shallow_tracer.ipynb. It avoids rasterization of the figures and looks just as nice as the widget version. However, it uses a different approach; it replaces the contents of the plot objects rather than creating a new plot each time. I think this is a preferable approach in general, but it takes a bit more work and it's different from most of our code for the book. The problem here is that the inline matplotlib backend and the JSAnimation code expect different things.

For the links in the introduction, it might be nice to refer to chapters rather then filenames; e.g.

[The chapter on shallow water](Shallow_water.ipynb)

rather than

[Shallow_water.ipynb](Shallow_water.ipynb)

@ketch
Copy link
Member

ketch commented Apr 25, 2017

One other issue: personally, I think it would be better if these widgets started with t=0. But for the print book we'll want to use a non-zero time.

@rjleveque
Copy link
Member Author

@ketch: I changed to t=0 but your modification of snapshot_widgets.py in #69 doesn't reset to t=0.2 because elsewhere t=0 is converted to t=0.001 to avoid a divide by zero at the initial time.

@rjleveque
Copy link
Member Author

This is rather clumsy but I managed to make a version of interact that creates a JSAnimation instead of the interactive widget. I had to introduce a fig parameter to get this to work properly for all three styles of interact since for JSAnimation it has to accumulate a list of figures.

It is illustrated in Introduction.ipynb.

@maojrs
Copy link
Contributor

maojrs commented May 2, 2017

Just tried the interacts with JSAnimation; they work quite well for me. Nothing clumsy.

@rjleveque
Copy link
Member Author

What's clumsy is that the function exact_solvers/shallow_water.plot_shallow_water_demo has to take a parameter fig and uses this to determine whether to show the figures or not depending on whether JSAnimation is being used, and then in the Introduction.ipynb notebook fig=ipywidgets.fixed(0) is passed in so that it doesn't make a widget for the parameter fig.

So this jsanimate.interact can't be used in other notebooks currently or it produces plots at all output times, not what we want. Making it work more generally would require modifying a bunch of our other functions that make plot functions and corresponding calls to animate.

For now at least I think it's ok to just have the jsanimate version in the Introduction, and then we can discuss later whether to try to make it work more generally.

rjleveque added 3 commits May 6, 2017 13:29
* master: (23 commits)
  Updated nbstripout to remove metadata
  Merged pull request
  Editorial changes to Tammann notebook.
  Added characterisitics
  Added section in negative pressure
  Minor changes to examples
  Put repeated code into a function.
  Update Docker.md
  Update Docker.md
  Minor update to TammannNB
  Fix a couple more typos.
  Fix a typo.
  Don't show delta shocks when t=0.
  Add exercise regarding low Froude number limit.
  Add references and notes on large Froude number limit in pressureless flow chapter.
  Forgot to nbstrip on previous commit
  Added examples to Euler Tammann NB
  Updated Tammann book
  revert dirty notebooks commited by accident
  Add clawpack to Dockerfile and instructions for pulling from riemann@master
  ...
@rjleveque
Copy link
Member Author

@ketch: do you understand why Travis is failing?

@rjleveque
Copy link
Member Author

I suggest closing this in favor of #71.

@rjleveque rjleveque merged commit 442fde2 into clawpack:master May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants